package cn.edu.swu.cly;

//***** Java代码学习 *****//
//public修饰的方法可以在Main中调用，private修饰的方法不能 直接 在Main调用

import javax.naming.Name;

public class Student {

    private String id;
    private String name;
    private String gender;
    private int age;
    //*****  带参构造函数 *****//
    public Student(String id, String name, String gender, int age) {
        this.id = id;
        this.name = name;
        setGender(gender);          //性别信息检验
        this.age = age;
    }

    //*****  无参构造函数  *****//
    public Student() {
        //还未使用
    }

    //*****  getter和setter方法  *****//
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        if ("男".equals(gender) || "女".equals(gender)) {
            this.gender = gender;
        } else {
            System.out.println("学生 " +this.name + " 输入的性别无效");
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    //***** showInfo方法 目标：有序输出学生所有信息 *****//
    public void showInfo() {
        System.out.println("学号:" + id);
        System.out.println("姓名:" + name);
        System.out.println("性别:" + gender);
        System.out.println("年龄:" + age);
    }
}
